#include "Util/Logger.h"
// implementation scope dependencies
#include <string>
#include <cstdarg>

Logger::Logger(const char* log) {
    m_Stream.open(std::string(log) + ".log");
}

Logger::~Logger() {
    m_Stream.flush();
    m_Stream.close();
}

//http://msdn.microsoft.com/en-us/library/w05tbk72.aspx // _vscprintf_s
//http://msdn.microsoft.com/en-us/library/d3xd30zz.aspx // _vsnprintf_s
void Logger::Write(const char* file, const char* method, const unsigned long line, const char* format, ...) {
    va_list args;
    va_start(args, format);
    
    const int len = _vscprintf(format, args);
    char* buffer = new char[len + 1];
    _vsnprintf_s(buffer, len + 1, len, format, args);
    va_end(args);
    
    m_Stream <<
        file << ":" <<
        line << " " <<
        method << " " <<
        buffer <<
        std::endl;
    
    SAFE_DELETE_A(buffer);
}